package com.OnTimeTeam.OnTime;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class DetailedTrack extends Activity {
	
	
    ListView list;
	BinderDataSubTracks adapter = null; 
	Track track;
	int position;
	ArrayList<Track.SubTrack> subTracks;
	
	Button buttonOk;
	Button buttonCancel;
	LinearLayout bottomBar;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.detailed_track);
   
        Intent i = getIntent();
        track = (Track)i.getSerializableExtra("track");
        position = i.getIntExtra("position",0);
    
        subTracks = new ArrayList<Track.SubTrack>();
        subTracks = track.getSubTracks();
        
        BinderDataSubTracks bindingData = new BinderDataSubTracks(this, subTracks, track, this.getBaseContext());
		list = (ListView) findViewById(R.id.sub_tracks_list);
		
		 buttonOk = (Button)findViewById(R.id.bSave);
	     buttonCancel = (Button)findViewById(R.id.bCancel);
	     bottomBar = (LinearLayout)findViewById(R.id.bottomBar);
	     
	     
	     if(i.getExtras().getBoolean("isLink"))
	    	 bottomBar.setVisibility(View.INVISIBLE);

		//Need to initialize text view (from track) above and beneath list: 
		//departure address, arrival address, total duration

		Log.i("BEFORE", "<<------------- Before SetAdapter------SubTracks-------------->>");

		list.setAdapter(bindingData);

		Log.i("AFTER", "<<------------- After SetAdapter-----SubTracks-------------->>");

		list.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

							}
		});


		  buttonOk.setOnClickListener(new Button.OnClickListener(){
		    	
		    	public void onClick(View v){
		    	
		    		Intent returnIntent = new Intent();
		        	returnIntent.putExtra("position",position);
		        	setResult(RESULT_OK,returnIntent);     
		        	finish();
					
		    		
		    	}
		    });
		    
		    buttonCancel.setOnClickListener(new Button.OnClickListener(){
		    	
		    	public void onClick(View v){
		    	
		    		Intent returnIntent = new Intent();
		        //	returnIntent.putExtra("position",position);
		        	setResult(RESULT_CANCELED,returnIntent);    
		        	finish();
		        	
		    	}
		    });
		  


		
    }


    

}
